package com.xyy.kingdeejdy.utils.jdy;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.smecloud.apigw.client.ApigwClient;
import com.smecloud.apigw.constant.HttpMethod;
import com.smecloud.apigw.model.ApiRequest;
import com.smecloud.apigw.model.ApiResult;
import com.xyy.kingdeejdy.pojo.erp.help.JdyApp;
import com.xyy.kingdeejdy.pojo.erp.help.JdyAuthorize;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class JdySecret {
    private static  JdyApp jdyApp;

    public static synchronized JdyApp get() {

        if (jdyApp != null) {
            return jdyApp;
        }
        ApiRequest request = new ApiRequest(HttpMethod.POST_FORM, "api.kingdee.com", "/jdyconnector/app_management/push_app_authorize");
        Map<String, String> map = new HashMap<>();
        map.put("outerInstanceId", "107980925391998976");
        request.setFormParam(map);
        request.setBodyJson(JSONObject.toJSONString("").getBytes());
        ApiResult result = ApigwClient.getInstance().send(request);
        JdyAuthorize jdyAuthorize = JSON.parseObject(result.getBody(), JdyAuthorize.class);
        List<JdyApp> data = jdyAuthorize.getData();
        jdyApp = data.get(0);
        return jdyApp;
    }
}
